<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
       	 个人信息
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="./css/index.css" media="all">
    <style>
        .imgs{display: none;}
        input[type="file"]{
            width: 50px;
            height:50px;
            border-radius: 100%;
            opacity:0;
            cursor:pointer;
            border: 1px solid red;
            position: absolute;
        }
    </style>

</head>
<body>

<div class="x-body">
     <form class="layui-form layui-form-pane" id="updateAdmin" action="../AdminInfo" method="POST" enctype="multipart/form-data" >
        <blockquote class="layui-elem-quote">
            <input type="hidden" name="id" value="8">
             <!--   添加隐藏域,传递id -->
             <!-- <input type="hidden" name="op" value="admin_change"> -->
             <input type="hidden" name="adminId" value=${sessionScope.ADMIN_LOGIN.adminId}>
            <div >
                <input class="layui-upload " type="file" accept="undefined" id="previewImg" name="images" >
                <img src="../FileDownloadServlet?type=image&fileName=${sessionScope.ADMIN_LOGIN.adminImgPath}" class="layui-circle" style="width:50px;height:50px;float:left" id="pimages" name="pimages"   alt="" >
                <input id="avatar"   name="image" required="" type="hidden" value="" >
                <dl style="margin-left:80px; color:#019688">
                    <dt><span >${sessionScope.ADMIN_LOGIN.nickname}</span> <span ></span></dt>
                </dl>
            </div>
        </blockquote>
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">

				
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>用户名
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="nickname" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value=${sessionScope.ADMIN_LOGIN.nickname}>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>手机号码
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="mobile"  autocomplete="off" placeholder=""
                                   class="layui-input" value=${sessionScope.ADMIN_LOGIN.mobile}>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>密码
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="adminPassword" value=${sessionScope.ADMIN_LOGIN.adminPassword} autocomplete="off" placeholder=""
                                   class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn" type="submit" lay-filter="add" lay-submit="">
                           		 保存
                        </button>
                    </div>
                    <!--</form>-->
                    <div style="height:100px;"></div>
                </div>

            </div>

        </div>
    </form>
</div>
<script src="./js/jquery-form.js"></script>
<script src="./js/jquery.js"></script>
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script>
	$(function(){
		// 根据id查询所有信息方法
		
		// 2.异步提交表单
		$("#updateAdmin").submit(function(){
			// 异步提交表单
			$(this).ajaxSubmit(function(result){
			/* 	 // 提示
				 layui.use('layer', function(){
					 layer.msg(result,{icon:1,time:2000});
					
				 }); */
				 // 关闭当前子窗口
				 var index = parent.layer.getFrameIndex(window.name);
                 parent.layer.close(index);
			});
			// 限制默认的表单提交
			return false;
		});
		// 3.生成图片预览
		$("#previewImg").change(function(){
			// 加入前端对上传文件内容类型和大小限制
			// 获取上传的文件
			let imgFile = this.files[0];
			// 判断是否有选择文件
			if(imgFile != null){
				// 正则表达式验证选择的文件是否是限制的MIME类型
				let regexImageFilter = /^(?:image\/png|image\/jpeg|image\/jpg)$/; 
				// 匹配
				if(!regexImageFilter.test(imgFile.type)){
					 layui.use('layer', function(){
							layer.msg("请选择有效的图片:image/jpg,image/jpeg,image/png,image/gif",{icon:2,time:2000});
					 });
					 $("#previewImg").val("");
					
				}else if(imgFile.size > 40000){
					 layui.use('layer', function(){
							layer.msg("图片大小不能超过40K",{icon:2,time:2000});
					 });
					 $("#previewImg").val("");
				}else{
					// 生成预览图
					// 构建文件读取流对象
					let fileReader = new FileReader();
					// 利用读取流对象读取文件的内容
					fileReader.readAsDataURL(imgFile);
					// 利用读取流对象加载事件
					fileReader.onload = function(){
						// 将头像显示在指定的框中
						document.getElementById("pimages").src = this.result;
					}
				}
			}else{
				document.getElementById("pimages").src = "";
			}
			
		});
		
	})


</script>

<script>
/*     layui.use(['element','layer','form'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form() */



        //图片上传接口
        /*layui.upload({
          url: './upload.json' //上传接口
          ,success: function(res){ //上传成功后的回调
              console.log(res);
            $('#LAY_demo_upload').attr('src',res.url);
          }
        });*/


 /*    }) */
</script>
<!--栏目缩略图上传-->
<script>
   /*  function upload(obj,id){
        var formData = new FormData();
        formData.append('images', $('#previewImg')[0].files[0]);
        formData.append('id', id);
        layer.msg('图片上传中', {icon: 16});
        $.ajax({
            type:"post",
            processData: false,
            contentType: false,
            url:"xxx",
            data:formData,
            success:function(data){
                if(data.status == 1){
                    console.log(data.image_name);
                    layer.closeAll('loading');
                    //layer.msg(data.info,{icon:1,time:1000});
                    $("#pimages").attr('src',data.image_name);
                    $("#avatar").val(data.image_name);
                    $(".imgs").show();
                    return false;
                }else{
                    layer.msg(data.info,{icon:2,time:1000});
                }
            }
        });
    } */
</script>

</body>
</html>